package com.eedi.framework.tenant.controller.sys;

import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.tenant.controller.sys.vo.setup.SysSetupShortcutCreateReq;
import com.eedi.framework.tenant.controller.sys.vo.setup.SysSetupShortcutResp;
import com.eedi.framework.tenant.controller.sys.vo.setup.SysSetupShortcutUpReq;
import com.eedi.framework.tenant.service.SysSetupShortcutService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;
import static com.eedi.framework.common.pojo.CommonResult.success;

/**
 * 系统界面 - 快捷方式设置
 * @author zybourn
 */
@Tag(name = "系统界面 - 快捷方式设置")
@RestController
@RequestMapping("/setup/shortcut")
public class SysSetupShortcutController {
    @Resource
    SysSetupShortcutService sysSetupShortcutService;

    @PostMapping("/create")
    @Operation(summary = "创建快捷方式")
    @PreAuthorize("@sys.hasPermission('sys:setup:shortcut-create')")
    public CommonResult<Void> create(@RequestBody SysSetupShortcutCreateReq req) {
        sysSetupShortcutService.crate(req);
        return success(null);
    }

    @PutMapping("/update")
    @Operation(summary = "更新快捷方式")
    @PreAuthorize("@sys.hasPermission('sys:setup:shortcut-update')")
    public CommonResult<Void> update(@RequestBody SysSetupShortcutUpReq req) {
        sysSetupShortcutService.update(req);
        return success(null);
    }

    @GetMapping("/list")
    @Operation(summary = "列表")
    @PermitAll
    public CommonResult<List<SysSetupShortcutResp>> list() {
        return success(sysSetupShortcutService.list());
    }

}
